/*
 * Copyright (c) United Binary LLC.  All rights reserved.
 * 
 * This code is licensed under the MIT License
 * 
 * SEE: http://harnessit.codeplex.com/license
 * 
 */
using System;
using System.IO;
using System.Runtime.CompilerServices;

namespace UnitedBinary.HarnessIt
{
	internal class EmergencyLog
	{
		private static readonly string logPath;
		private const string logFile = "execution.log";

		static EmergencyLog()
		{
			logPath = AppDomain.CurrentDomain.BaseDirectory;
			if (!logPath.EndsWith("\\"))
			{
				logPath += "\\";
			}
			logPath += logFile;
		}
	
		private EmergencyLog() {}

		[MethodImpl(MethodImplOptions.Synchronized)]
		internal static void WriteLine(string message, string details)
		{
			StreamWriter writer = null;
			try
			{
				writer = File.AppendText(logPath);
				writer.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
				writer.Write(" - ");
				writer.WriteLine(message);
				writer.WriteLine(details);
				writer.Flush();
			}
			finally
			{
				if (writer != null)
				{
					writer.Close();
				}
			}
		}
	}
}
